package com.cg.design.graphicdesignpattern.abstractfactory;

import com.cg.design.graphicdesignpattern.abstractfactory.factory.Factory;
import com.cg.design.graphicdesignpattern.abstractfactory.factory.Link;
import com.cg.design.graphicdesignpattern.abstractfactory.factory.Page;
import com.cg.design.graphicdesignpattern.abstractfactory.factory.Tray;
import org.junit.Test;

import java.util.Scanner;

/**
 * AbstractFactory抽象工厂模式测试类
 *
 * @program: LeetCode->AbstractFactoryTest
 * @description: AbstractFactory抽象工厂模式测试类
 * @author: cg
 * @create: 2022-03-21 20:32
 **/
public class AbstractFactoryTest {

    @Test
    public void testAbstractFactory() {
        Scanner input = new Scanner(System.in);
        System.out.println("Example 1: com.cg.design.graphicdesignpattern.abstractfactory.listfactory.ListFactory");
        System.out.println("Example 2: com.cg.design.graphicdesignpattern.abstractfactory.tablefactory.TableFactory");

        Factory factory = Factory.getFactory(input.next());

        Link people = factory.createLink(" 人民日报 ", "http://www.people.com.cn/");
        Link gmw = factory.createLink(" 光明日报  ", "http://www.gmw.cn/");

        Link us_yahoo = factory.createLink("Yahoo!", "http://www.yahoo.com/");
        Link jp_yahoo = factory.createLink("Yahoo!Japan", "http://www.yahoo.co.jp/");
        Link excite = factory.createLink("Excite", "http://www.excite.com/");
        Link google = factory.createLink("Google", "http://www.google.com/");

        Tray trayNews = factory.createTray(" 日报 ");
        trayNews.add(people);
        trayNews.add(gmw);

        Tray trayYahoo = factory.createTray("Yahoo!");
        trayYahoo.add(us_yahoo);
        trayYahoo.add(jp_yahoo);

        Tray traySearch = factory.createTray(" 搜索引擎 ");
        traySearch.add(trayYahoo);
        traySearch.add(excite);
        traySearch.add(google);

        Page page = factory.createPage("LinkPage", " Chenyumeng ");
        page.add(trayNews);
        page.add(traySearch);
        page.output();
    }

}
